@echo off
set targetApk=%1
set targetApkName=%~n1
echo apkName is %targetApkName%

@rem set variables.
set KEYSTORE_PATH=%3
@REM set KEYSTORE_PATH=C:\WorkSpace_zl\project\chengju\drivingtest\keystore.jks
set KEYSTORE_PASS=123456
@REM set KEY_ALIAS=android.keystore
set KEY_ALIAS=%4
set KEY_PASS=123456
set DIRNAME=%~dp0
set CHANNEL=%2
set outDir=apks


echo %DIRNAME%

@rem align apk
echo ===============start zipalign =====================
zipalign.exe -v -p 4 %targetApk% %targetApkName%-aligned.apk
echo ===============done zipalign =====================

@rem sign apk
echo ===============start sign =====================
start apksigner.bat sign --v1-signing-enabled true --v2-signing-enabled true --ks %KEYSTORE_PATH% --ks-key-alias %KEY_ALIAS% --ks-pass pass:%KEYSTORE_PASS% --key-pass pass:%KEY_PASS%  --out %targetApkName%-signed.apk %targetApkName%-aligned.apk
TIMEOUT /t 3
echo =============== signed successful =====================


@rem vas dolly 
echo ===============VasDolly processing =====================
java.exe -jar %DIRNAME%\VasDolly.jar put -c %CHANNEL% %targetApkName%-signed.apk  %outDir%
@REM java.exe -jar %DIRNAME%\VasDolly.jar get %outDir%/%targetApkName%-signed.apk
echo ===============VasDolly successful =====================

@rem clear cache
echo ===============clear temp files ==================
DEL *.idsig
DEL %targetApkName%-aligned.apk
DEL %targetApkName%-signed.apk 
echo ===============temp files cleared.==================